# 对应CSDN python系列专栏博客
# 对应2024/04/13 的python博客
# 主题：从零开始学习Python中的随机模块：实现验证码生成功能
# 2024/04/15 发布

# 2.1 choice
import random

my_list = [1, 2, 3, 4, 5]
print(random.choice(my_list))

# randint
import random

# 生成 1 到 10 之间的随机整数
random_number = random.randint(1, 10)
print(random_number)

# 四位数的数字验证码

import random

chptcha = ""

for i in range(4):
    chptcha = chptcha + str(random.randint(0,9))

print(f"四位数字验证码:{chptcha}")

# 四位的字母数字验证码

import random
import string

characters = string.ascii_letters + string.digits

captcha = ''

for i in range(4):
    captcha += random.choice(characters)

print("字母数字验证码:", captcha)

# 生成一个强密码

import random
import string

characters = string.ascii_letters + string.digits + string.punctuation

password = ''

for i in range(8):
    password += random.choice(characters)

print("强密码:", password)